//
//  list_change_node.hpp
//  cpp_algorithm
//
//  Created by 李贺 on 2021/12/2.
//

#ifndef list_change_node_hpp
#define list_change_node_hpp

#include <stdio.h>
#include <vector>
#include <iostream>
using namespace std;

class ListNode {
        
public:
    int val;
    ListNode *next;
    ListNode(int x): val(x),next(NULL){}
};

class Solution_list_changenode {
    
public:
    ListNode *swapPairs(ListNode *head) {
        ListNode *dummyHead = new ListNode(0);
        dummyHead->next = head;
        ListNode *cur = dummyHead;
        
        while (cur->next != nullptr && cur->next->next != nullptr) {
            ListNode *temp = cur->next;
            ListNode *temp1 = cur->next->next->next;
            
            cur->next = cur->next->next;
            cur->next->next = temp;
            cur->next->next->next = temp1;
            
            cur = cur->next->next;
            
        }
        return dummyHead->next;
    }
    
};

#endif /* list_change_node_hpp */
